package com.ruoyi.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.equipment.domain.TTools;
import com.ruoyi.equipment.service.ITToolsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工具字典Controller
 * 
 * @author ruoyi
 * @date 2021-12-29
 */
@RestController
@RequestMapping("/facility/tools")
public class TToolsController extends BaseController
{
    @Autowired
    private ITToolsService tToolsService;

    /**
     * 查询工具字典列表
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTools tTools)
    {
        startPage();
        List<TTools> list = tToolsService.selectTToolsList(tTools);
        return getDataTable(list);
    }

    @GetMapping("/listTree")
    public TableDataInfo list(){
        Long deptId = getDeptId();
        int i = deptId.intValue();
        TTools tTools = new TTools();
        tTools.setDeptId(i);
        List<TTools> tTools1 = tToolsService.selectTToolsList(tTools);
        return getDataTable(tTools1);
    }


    /**
     * 导出工具字典列表
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:export')")
    @Log(title = "工具字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTools tTools)
    {
        List<TTools> list = tToolsService.selectTToolsList(tTools);
        ExcelUtil<TTools> util = new ExcelUtil<TTools>(TTools.class);
        util.exportExcel(response, list, "工具字典数据");
    }

    /**
     * 获取工具字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:query')")
    @GetMapping(value = "/{toolId}")
    public AjaxResult getInfo(@PathVariable("toolId") Long toolId)
    {
        return AjaxResult.success(tToolsService.selectTToolsByToolId(toolId));
    }

    /**
     * 新增工具字典
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:add')")
    @Log(title = "工具字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTools tTools)
    {
        //sout
        return toAjax(tToolsService.insertTTools(tTools));
    }

    /**
     * 修改工具字典
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:edit')")
    @Log(title = "工具字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTools tTools)
    {
        return toAjax(tToolsService.updateTTools(tTools));
    }

    /**
     * 删除工具字典
     */
    @PreAuthorize("@ss.hasPermi('facility:tools:remove')")
    @Log(title = "工具字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{toolIds}")
    public AjaxResult remove(@PathVariable Long[] toolIds)
    {
        return toAjax(tToolsService.deleteTToolsByToolIds(toolIds));
    }
}
